package ucuenca.server;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DB_Conn {
	
	public DB_Conn() {
		
		// figure out what server this application is being hosted on
		getServerMysqlOn();
	}

	private void getServerMysqlOn() {

	}
	
	protected Connection getConn() {
	
		    Connection conn	= null;
		    
		    // figure out what server this application is being hosted on
		    String url 		= getServerURL();
		    
		    String db 		= "sistemaempresa";
		    String driver 	= "com.mysql.jdbc.Driver";
		    String user 	= "root";
		    String pass 	= "soloyose";
		    
		    try {
		      
		    	Class.forName(driver).newInstance();
		    	conn = DriverManager.getConnection(url+db, user, pass);
		      
		    } catch (InstantiationException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (ClassNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
		    return conn;
	}
	
	private String getServerURL() {
		String url = "jdbc:mysql://localhost:3306/";
			
		return url;
	}
	
	protected static int getResultSetSize(ResultSet resultSet) {
	    int size = -1;

	    try {
	        resultSet.last();
	        size = resultSet.getRow();
	        resultSet.beforeFirst();
	    } catch(SQLException e) {
	        return size;
	    }

	    return size;
	}
		

}
